<?php // $Id: index.php,v 1.7.2.2 2009/03/31 13:07:21 mudrd8mz Exp $

/**
 * This page lists all the instances of ltcd in a particular course
 *
 * @author  Your Name <your@email.address>
 * @version $Id: index.php,v 1.7.2.2 2009/03/31 13:07:21 mudrd8mz Exp $
 * @package mod/ltcd
 */


require_once(dirname(dirname(__FILE__)).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/lconfig.php');

print_header($strlicense, $strlicense, $navigation, "", "", false, "&nbsp;", "&nbsp;");
//Check if module is configured yet...
if(!isset($LCFG) || !($LCFG instanceOf Object) || $LCFG->username == '' || $LCFG->password == ''){
	error('This module needs to be configured before you can use it! <a style="font-weight:bold;" href="config_ltcd.php">click here to configure it!</a>');
}

//Get data from POST
if(isset($_POST['password']) && trim($_POST['password']) != ''){
	$pass = trim($_POST['password']);
}else{
	error('Empty password provided! <a href="index.php">&lt;-Back to the Form</a>');
}
if(isset($_POST['username']) && trim($_POST['username']) != ''){
	$username = trim($_POST['username']);
}else{
	error('Empty username provided! <a href="index.php">&lt;-Back to the Form</a>');
}
if(isset($_POST['group']) && intval($_POST['group']) > 0){
	$group = intval($_POST['group']);
}else{
	error('No group selected! <a href="index.php">&lt;-Back to the Form</a>');
}
if(isset($_POST['classname']) && trim($_POST['classname']) != ''){
	$classname = trim($_POST['classname']);
}else{
	$classname = "";
}

//Get the users, and build XML to send
$ltcd_data = new SimpleXMLElement('<class_import></class_import>');
$meta = $ltcd_data->addChild('metadata','');
$meta->addChild('cipher','rijndael-128-cbc');
$meta->addChild('encoding','base64');
$meta->addChild('keyhash_algo','sha1');
$ltcd_data->addChild('username',$username);
$ltcd_data->addChild('password',$pass);
$xml = $ltcd_data->addChild('data');
//Init settings
$meta = $xml->addChild('metadata');
$meta->addChild('classname',$classname);
$meta->addChild('source','moodle');

$user_block = $xml->addChild('users');
$users = get_group_students($group);
foreach($users as $user){
	$usr = $user_block->addChild('user');
	$usr->addChild('username',$user->username);
	$usr->addChild('password',$user->password);
	$usr->addChild('school',$user->school);
	$usr->addChild('deleted',$user->deleted);
	$usr->addChild('firstname',$user->firstname);
	$usr->addChild('lastname',$user->lastname);
	$usr->addChild('email',$user->email);
	$usr->addChild('skype',$user->skype);
	$usr->addChild('phone',$user->phone1);
	$usr->addChild('address',"City: ".$user->city."; Street: ".$user->address."; Zip:");
	$usr->addChild('country',$user->country);
}

//Sync users

sync_users(0, urlencode(base64_encode($ltcd_data->asXML())));

print_footer('none');


?>

